<template>
  <BasicDrawer
    v-bind="$attrs"
    @register="registerDrawer"
    :title="getTitle"
    width="700px"
    @ok="handleSubmit"
    destroyOnClose
  >
    <BasicForm @register="registerForm" />
    <div style="margin-bottom: 20px; display: inline-block">
      <div class="divBody">
        <span>目标ip： {{ dataList.ipAddress }}</span>
        <span>请求方法： {{ dataList.method }}</span>
        <span>请求时间： {{ dataList.stopwatch }}</span>
      </div>
      <div class="divBody">
        <span>请求路径： {{ dataList.requestUrl }}</span>
        <span>操作人： {{ dataList.userName }}</span>
        <span>操作时间： {{ dataList.createdTime }}</span>
        <span>返回状态： {{ dataList.statusCode }}</span>
      </div>
    </div>
    <div class="bomDiv">
      <span style="margin-top: 40px">描述：</span>
      <span class="spanText">{{ dataList.describe }}</span>
    </div>
  </BasicDrawer>
</template>
<script lang="ts" setup>
import { ref, computed, unref, useAttrs } from "vue";
import { BasicForm, useForm } from "/src/components/Form";
import { BasicDrawer, useDrawerInner } from "/src/components/Drawer";
import { BasicTree, TreeItem } from "/src/components/Tree";
import { formSchema } from "./index.data";
import { useSuccess } from "/@/hooks/rw/handleSuccess";
const { rhandleSuccess } = useSuccess();
// 声明Emits
const emit = defineEmits(["success", "register"]);
const attrs = useAttrs();
const isUpdate = ref(true);
const dataList = ref<Person>({});
const [registerForm, { setProps, resetFields, setFieldsValue, validate }] = useForm({
  labelWidth: 90,
  schemas: formSchema,
  showActionButtonGroup: false,
});
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
  resetFields();
  dataList.value = data.record;
  isUpdate.value = !!data?.isUpdate;
  setDrawerProps({ confirmLoading: false });
  if (unref(isUpdate)) {
    setFieldsValue({
      ...data.record,
    });
  }
  //禁用表单
  setProps({ disabled: !attrs.showFooter });
});
/**
 * 标题
 */
const getTitle = computed(() => (!unref(isUpdate) ? "" : "详情"));
/**
 * 提交
 */
async function handleSubmit() {
  try {
    closeDrawer();
    emit("success");
  } finally {
    setDrawerProps({ confirmLoading: false });
  }
}
</script>
<style lang="less" scoped>
.leftImg {
  display: inline-block;
  width: 100px;
  height: 100px;
  margin-right: 30px;
  vertical-align: bottom;
}
.bottomImg {
  display: inline-block;
  width: 60px;
  height: 60px;
  margin-right: 20px;
  vertical-align: bottom;
}
.spanText {
  color: #666;
}
.divBody {
  display: inline-block;
  width: 205px;
  span {
    display: inline-block;
    margin-bottom: 5px;
    font-size: 12px;
    width: 100%;
  }
}
.bomDiv {
  margin-top: 10px;
  span {
    font-size: 12px;
    display: block;
    margin-bottom: 8px;
  }
}
.divBodyBom {
  margin-top: 95px;
  float: right;
  margin-right: 150px;
  span {
    display: inline-block;
    margin-bottom: 5px;
    font-size: 12px;
    width: 100%;
  }
}
</style>
